#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    //新增一个标签页
    int count = ui->tabWidget->count();
    QWidget* new_widget = new QWidget();
    QLabel* label = new QLabel(new_widget);
    label->move(200,150);
    label->setText("标签" + QString::number(count+1));
    ui->tabWidget->addTab(new_widget,"tab" + QString::number(count + 1));
}

void Widget::on_pushButton_2_clicked()
{
    int index = ui->tabWidget->currentIndex();
    if(index == -1)
        return;
    qDebug() << "删除 " << index << "页";
    ui->tabWidget->removeTab(index);
}

void Widget::on_tabWidget_tabCloseRequested(int index)
{
    //关闭请求
    qDebug() << "关闭 " << index << "页";
    ui->tabWidget->removeTab(index);
}
